package homework.sort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {


    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        // 初始化配置类和job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //设置驱动类
        job.setJarByClass(SortDriver.class);

        //设置mapper和reducer
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);

        //设置mapper的输出key，value类型
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(Text.class);

        //设置最终输出的key,value类型
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);

        //设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path("/Users/shiyuhou/BigdataProjects/hadoop-homework/sourceData"));
        FileOutputFormat.setOutputPath(job,new Path("/Users/shiyuhou/BigdataProjects/hadoop-homework/outData"));

        //启动job
        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);
    }
}
